package com.huan.social.weixin.connect;

import com.huan.social.weixin.api.Weixin;
import com.huan.social.weixin.api.impl.WeixinTemplate;
import lombok.Getter;
import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;

/**
 * 微信 服务提供商
 *
 * @author huan.fu
 * @date 2018/9/27 - 11:37
 */
public class WeixinServiceProvider extends AbstractOAuth2ServiceProvider<Weixin> {

	@Getter
	private String userInfoUrl;

	public WeixinServiceProvider(String clientId, String clientSecret, String userInfoUrl, String authorizeUrl, String accessTokenUrl, String refreshTokenUrl) {
		super(new WeixinOauth2Template(
				clientId,
				clientSecret,
				authorizeUrl,
				accessTokenUrl,
				refreshTokenUrl
		));
		this.userInfoUrl = userInfoUrl;
	}

	@Override
	public Weixin getApi(String accessToken) {
		return new WeixinTemplate(this.getUserInfoUrl(), accessToken);
	}
}
